// 引入axios
import axios from "axios";

// 引入基础路径
import { baseURL } from "../config";
// import { get } from "core-js/fn/dict";

// 考试页面轮播图
function HomeSlideShow() {
  return new Promise(function(resolve) {
    axios.get(baseURL + "app/cms/cmsgg").then(res => {
      resolve(res.data);
    });
  });
}

// 学车课堂
function CardSchool() {
  return new Promise(function(resolve) {
    axios.get(baseURL + "app/cms/cmsxckt/1").then(res => {
      resolve(res.data);
    });
  });
}

// 学车课堂详情页
function CardDetails(lid) {
  return new Promise(function(resolve) {
    axios
      .get(`${baseURL}app/cms/cmsxcktBy/${lid}`)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 学车课堂评论
function CardReview(lid) {
  return new Promise(function(resolve) {
    axios
      .get(`${baseURL}app/cms/cmsKtPllist/${lid}`)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 学车课堂列表页
function CardList() {
  return new Promise(function(resolve) {
    axios.get(baseURL + "app/cms/cmsxckt/2").then(res => {
      resolve(res.data);
    });
  });
}

// 驾考秘籍
function CardCheats(type) {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "app/cms/cmsjkmj/1/" + type)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 驾考列表
function CardLists(type) {
  return new Promise(function(resolve) {
    axios.get(baseURL + "app/cms/cmsjkmj/2/" + type).then(res => {
      // console.log(res);
      resolve(res.data);
    });
  });
}

// 学车学堂评论留言
function driverComments(remork) {
  return new Promise(function(resolve) {
    axios
      .post(baseURL + "user/app/cmsInsertKtPl", remork)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 驾考秘籍详情
function DrivingDetals(lid) {
  return new Promise(function(resolve) {
    axios.get(`${baseURL}app/cms/cmsjkmjby/${lid}`).then(res => {
      console.log("我是id:" + lid);
      resolve(res.data);
    });
  });
}

// 驾考秘籍详情评论
function DrivingComment(lid) {
  return new Promise(function(resolve) {
    axios.get(`${baseURL}app/cms/cmsMjPllist/${lid}`).then(res => {
      resolve(res.data);
    });
  });
}

// 驾考秘籍评论留言
function CardComments(remork) {
  return new Promise(function(resolve) {
    axios
      .post(baseURL + "user/app/cmsInsertMjPl", remork)
      .then(res => {
        // console.log(res);
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 顺序练习
function OrderExercise(type, km, tlx) {
  return new Promise(function(resolve) {
    axios
      .get(
        baseURL +
          "user/topic/toTestPath?chexing=" +
          type +
          "&kemu=" +
          km +
          "&tlx=" +
          tlx
      )
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 模拟答题
function SimulatedResult(type, km) {
  return new Promise(function(resolve) {
    axios
      .get(
        baseURL + "/user/topic/toExamTestPath?chexing=" + type + "&kemu=" + km
      )
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 加入错题本
function MistakesBook(obj) {
  return new Promise(function(resolve) {
    axios
      .post(baseURL + "user/topic/addWrong", obj)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 模拟考试加入错题本
function JoinErrors(id) {
  return new Promise(function(resolve) {
    axios
      .post(baseURL + "user/topic/examAddWrong", {
        examId: id
      })
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 错题本移除错题
function RemoveMistakes(obj) {
  return new Promise(function(resolve) {
    axios
      .post(baseURL + "user/topic/deleteByIds", obj)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 科一 ~ 科四的考点视频
function ExamVideo(type, sort) {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "app/cms/getCmsExamVideo/" + type + "/" + sort)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 科二视频详情
function VideoDetails(type, id) {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "app/cms/getByCmsExamVideo/" + type + "/" + id)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 顺序答题点击交卷时保存
function Conserve(obj) {
  return new Promise(function(resolve) {
    axios
      .post(baseURL + "user/topic/saveStuExamInfo", obj)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 错题本
function MistakesCollect() {
  return new Promise(function(resolve) {
    axios
      .post(baseURL + "user/topic/wronglist")
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 图标技巧
function PatternDesign(type) {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "app/cms/getByjtsign/" + type)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 图标详情
function MotifDesign(id) {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "app/cms/getByjtsignDetail/" + id)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 社区  ytpe 1:可以社区  2:科二社区  3:科三社区  4:科四社区
function SubscribeCommunity(type) {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "bbs/app/getBbslist/" + type)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 社区详情
function CommunityDetails(id) {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "bbs/app/getBbslistDetail/" + id)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 社区详情 评论列表
function DiscussList(id) {
  return new Promise(function(resolve) {
    axios
      .get(baseURL + "bbs/app/getBbslistDetailTl/" + id)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 社区详情 -> 评价
function CommunityAppraise(obj) {
  return new Promise(function(resolve) {
    axios
      .post(baseURL + "bbs/app/InsertBbsTl", obj)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

// 发布帖子
function IssueInvitation(obj) {
  return new Promise(function(resolve) {
    axios
      .post(baseURL + "bbs/app/addsave", obj)
      .then(res => {
        resolve(res.data);
      })
      .catch(err => {
        console.error(err);
      });
  });
}

export {
  HomeSlideShow,
  CardSchool,
  CardList,
  CardCheats,
  CardLists,
  CardDetails,
  DrivingDetals,
  driverComments,
  DrivingComment,
  CardComments,
  CardReview,
  OrderExercise,
  SimulatedResult,
  ExamVideo,
  VideoDetails,
  MistakesBook,
  Conserve,
  JoinErrors,
  MistakesCollect,
  PatternDesign,
  MotifDesign,
  SubscribeCommunity,
  CommunityDetails,
  DiscussList,
  CommunityAppraise,
  IssueInvitation,
  RemoveMistakes
};
